//
//  FlutterIosMapView.m
//  o_amap
//
//  Created by Q神 on 2021/4/9.
//

#import "FlutterIosMapView.h"
/// 导航
#import <AMapNaviKit/AMapNaviKit.h>
#import "HQMapManager.h"
#import "HQMapInitOptionsModel.h"
#import "MJExtension.h"

@interface FlutterIosMapView()

@property (nonatomic, strong) MAMapView *mapView;

@end

@implementation FlutterIosMapView {
    /// FlutterIosTextLabel 创建后的标识
    int64_t _viewId;
    /// 消息回调
    FlutterMethodChannel* _channel;
}


/// 在这里只是创建了一个View
- (instancetype)initWithWithFrame:(CGRect)frame viewIdentifier:(int64_t)viewId arguments:(id)args binaryRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar withMapPlugin:(NSObject<FlutterPlugin> * _Nonnull)mapPlugin streamHandler:(GdMapFlutterStreamHandler * _Nullable)handler {
    
    if ([super init]) {
        
        if (frame.size.width == 0) {
            frame = CGRectMake(frame.origin.x, frame.origin.y, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
        }
        
        self.mapView.frame = frame;
        [[HQMapManager shareInstance] mapViewWithRegistrar:registrar withMapPlugin:mapPlugin viewIdentifier:viewId withMapView:self.mapView streamHandler:handler];
        
        /// 初始化地图参数
        HQMapInitOptionsModel *model = [HQMapInitOptionsModel mj_objectWithKeyValues:args];
        NSLog(@"初始化地图参数==%@",args);
        if (model) {
            [model setParamsWithMapView:self.mapView];
        }
        
        _viewId = viewId;
    
    }
    return self;
}

#pragma mark -- FlutterPlatformView
/// 返回真正的视图
- (nonnull UIView *)view {
    return self.mapView;
}

#pragma mark -- 懒加载

- (MAMapView *)mapView {
    if (!_mapView) {
        _mapView = [[MAMapView alloc] init];
    }
    return _mapView;
}

@end
